<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-采购模板</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/manage.css" rel="stylesheet" type="text/css" />
<style>
	.edit-con img{width:120px;}
	.edit-inp{width:350px;}
	.edit-inp input{width:352px;}
	.edit-img span{display: block}
	
</style>
</head>

<body>
<%@ include file="/website/common/top.jsp"%>
<%@ include file="/website/common/head.jsp"%>
<%@ include file="/website/common/menu.jsp"%>

<div class="warp-body">
	<div class="inner clearfix">
    	<div class="left-main">
        	<div class="left-inner">
            	<%@ include file="/website/user/left.jsp"%>
            </div>
        </div>
    	<div class="right-main">
        	<div class="right-inner" style="background-color: #ffffff">
            	<div class="right-title"><span></span>采购模板</div>
            	<div class="ente-edit-info">
            		<div class="line8"></div>
            		<form action="" method="post" onsubmit="return false">
            		<input name="id" type="hidden" value="${bean.id }">
            		<ul>
            			<li class="edit-item">
                        	<div class="edit-inner">
                            	<div class="edit-title">采购计划标题*：</div>
                                <div class="edit-con">
                                	<div class="edit-inp"><input type="text" name="name" value="${bean.name }"></div>
                                	<div class="tips"></div>
                                </div>
                            </div>
                        </li>
                        <li class="edit-item">
                        	<div class="edit-inner">
                            	<div class="edit-title">采购计划说明：</div>
                                <div class="edit-con">
                                	<div class="edit-inp"><input type="text" name="explanation" value="${bean.explanation }"></div>
                                	<div class="tips"></div>
                                </div>
                            </div>
                        </li>
                        <li class="edit-item">
                        	<div class="edit-inner">
                            	<div class="edit-title">封面图片*：</div>
                                <div class="edit-con edit-img">
                                	<c:choose>
                                	<c:when test="${not empty bean.photo }">
                                		<span><img src="<%=getRandomFileserver()%>${bean.photo}"></span>
                                		<span id="imgupbtn" href="javascript:;"><a href="javascript:;">重新选择</a></span>
										<input type="hidden" name="photo" value="${bean.photo}">
                                	</c:when>
                                	<c:otherwise>
                                		<span id="imgupbtn"><img src="${webctx }/images/addimg.jpg"></span>
										<input type="hidden" name="photo">
                                	</c:otherwise>
                                	</c:choose>
                                </div>
                            </div>
                        </li>
                         <li class="edit-item clear">
                        	<div class="edit-inner">
                            	<div class="edit-title">&nbsp;</div>
                                <div class="edit-con edit-papers-btn">
                                	<c:choose>
                                	<c:when test="${not empty bean.id }">
                                		<button onclick="tosubmit()" style=" margin-left:0px;margin-top:10px;">保存</button>
                                	</c:when>
                                	<c:otherwise>
                                		<button onclick="tosubmit()" style=" margin-left:0px;margin-top:10px;">保存并添加商品</button>
                                		
                                	</c:otherwise>
                                	</c:choose>
                                </div>
                            </div>
                        </li>
            		</ul>
            		</form>
            	</div>
            </div>
        </div>
    </div>
</div>

<%@ include file="/website/common/foot.jsp"%>
<script type="text/javascript" src="${ctx}/plugins/plupload2/plupload.full.min.js"></script>
<script type="text/javascript" src="${ctx}/plugins/oss/upload.js"></script>
</body>
</html>
<script>
var uploader;
$(function(){
	setLeftCur("cgmb");
	
	var plparm={
			runtimes : 'html5,flash,silverlight,html4',
			browse_button :"imgupbtn",
		    multi_selection: false,
			flash_swf_url : ctx+'/plugins/plupload2/Moxie.swf',
			silverlight_xap_url : ctx+'/plugins/plupload2/Moxie.xap',
		    url : '',
		    filters: {
				max_file_size : '500kb',
				prevent_duplicates :false, //不允许选取重复文件
			  	mime_types : [ //只允许上传图片文件
			    { title : "图片文件", extensions : "jpg,png,jpeg,gif" }
			  	]
			},
			init: {
				FilesAdded: function(up, files) {
					if(up.files.length>1)
						up.removeFile(up.files[0]);
					if(files.length>0){
						var html="<div class='pl_upimgdiv' id='img_"+files[0].id+"'><img src='"+ctx+"/images/imgloading.png' style='width:100px'/><div class='progressbg'></div><div class='progresstxt'>等待上传</div></div>";
						$("#imgupbtn").prev().remove();
						$("#imgupbtn").html(html);
						$oss.previewImageOne(files[0],function(src){
							$("img",$('#img_'+files[0].id)).attr("src",src);
						})
					}
				},UploadFile:function(up,file){
					var f=$('#img_'+file.id);
					$(".progresstxt",f).show();
				},UploadProgress:function(up,file){
					var f=$('#img_'+file.id);
					var d=$(".progressbg",f);
					var w=f.width()*parseInt(file.percent)/100;
					d.css("width",w+"px");
					$(".progresstxt",f).html(file.percent+"%");
				},FileUploaded:function(up,file,responseObject){
					var re=jQuery.parseJSON(responseObject.response);
					$("input[name='photo']").val(re.url.replace(re.basepath,""));
				},UploadComplete:function(){
					tosave();
				}
			}
	}
	$oss.setUpDir("purchasetemps");
	uploader=$oss.initUpload(plparm);
})
var subing=false;
function tosubmit(){
	$(".tips").html('');
	if($("[name='name']").val()==''){
		$("[name='name']").parent().next().text("请填写标题");
		return;
	}else if($("[name='photo']").length==0){
		alert("请上传封面图片");
		return;
	}
	if(!subing){
		subing=true;
		if(uploader.files.length>0)uploader.start();
		else tosave();
	}
}
function tosave(){
	$w.httpRequest({
		url:apiroot+"/purchasetemp/save",
		data:$("form").serializeArray(),
		ok:function(ret){
			window.location.href=ctx+"/purchasetemp/addProductShow?panid="+ret.Data
		},all:function(){subing=false;}
	})
}
</script>